﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
using VO;
using Core;

namespace DAL
{
    public class HoaDonDAL:ketnoi
    {
        public bool _order_them(VO.HoadonVO data)
        {
            try
            {
                using (SqlCommand dbCmd = new SqlCommand("addorder", GetConnection()))
                {
                    dbCmd.CommandType = CommandType.StoredProcedure;
                    dbCmd.Parameters.Add(new SqlParameter("@MaHD", data.MaHD));
                    dbCmd.Parameters.Add(new SqlParameter("@MaNV", data.MaNV));
                    dbCmd.Parameters.Add(new SqlParameter("@MaDG", data.MaDG));
                    dbCmd.Parameters.Add(new SqlParameter("@NgayMuon", data.NgayMuon));
                    dbCmd.Parameters.Add(new SqlParameter("@NgayTra", data.NgayTra));
                    dbCmd.ExecuteNonQuery();
                }
            }
            catch
            {

            }

            return true;
        }
        public bool _order_view(VO.HoadonVO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("viewoeder", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@MaHD", data.MaHD));
                dbCmd.Parameters.Add(new SqlParameter("@MaDG", data.MaDG));
                dbCmd.Parameters.Add(new SqlParameter("@Gia", data.Gia));
                dbCmd.Parameters.Add(new SqlParameter("@MaSach", data.MaSach));
                dbCmd.Parameters.Add(new SqlParameter("@MaNV", data.MaNV));
                dbCmd.Parameters.Add(new SqlParameter("@NgayMuon", data.NgayMuon));
                dbCmd.Parameters.Add(new SqlParameter("@NgayTra", data.NgayTra));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public bool _order_edit(VO.HoadonVO data)
        {
            using (SqlCommand dbCmd = new SqlCommand("editorder", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@MaHD", data.MaHD));
                dbCmd.Parameters.Add(new SqlParameter("@MaDG", data.MaDG));
                dbCmd.Parameters.Add(new SqlParameter("@Gia", data.Gia));
                dbCmd.Parameters.Add(new SqlParameter("@MaSach", data.MaSach));
                dbCmd.Parameters.Add(new SqlParameter("@MaNV", data.MaNV));
                dbCmd.Parameters.Add(new SqlParameter("@NgayMuon", data.NgayMuon));
                dbCmd.Parameters.Add(new SqlParameter("@NgayTra", data.NgayTra));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public bool _order_delete(string MaHD)
        {
            using (SqlCommand dbCmd = new SqlCommand("delorder", GetConnection()))
            {
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@MaHD", MaHD));
                dbCmd.ExecuteNonQuery();
            }

            return true;
        }
        public DataTable hd_manv()
        {
            DataTable dt = new DataTable();
            using (SqlCommand dbCmd = new SqlCommand("hd_manv", GetConnection()))
            {
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
                da.Fill(dt);
            }

            return dt;
        }
        public DataTable hd_xem()
        {
            DataTable dt = new DataTable();
            using (SqlCommand dbCmd = new SqlCommand("hd_xem", GetConnection()))
            {
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
                da.Fill(dt);
            }

            return dt;
        }
        public DataTable hd_madg()
        {
            DataTable dt = new DataTable();
            using (SqlCommand dbCmd = new SqlCommand("hd_madg", GetConnection()))
            {
                SqlDataAdapter da = new SqlDataAdapter(dbCmd);
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.ExecuteNonQuery();
                da.Fill(dt);
            }

            return dt;
        }

    }
}
